#!/bin/bash
#
# 4shared.com module
# Copyright (c) 2010-2012 Plowshare team
#
# This file is part of Plowshare.
#
# Plowshare is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Plowshare is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Plowshare.  If not, see <http://www.gnu.org/licenses/>.

MODULE_SHARESIX_REGEXP_URL="http://\(\.\)\?sharesix\.com/"

MODULE_SHARESIX_DOWNLOAD_OPTIONS=""
MODULE_SHARESIX_DOWNLOAD_RESUME=yes
MODULE_SHARESIX_DOWNLOAD_FINAL_LINK_NEEDS_COOKIE=yes

MODULE_SHARESIX_LIST_OPTIONS=""

sharesix_download() {

local COOKIEFILE=$1
local URL=$2
	
	curl -c "$COOKIEFILE" -e "http://sharesix.com/auth/login" -d "username=jack44556677&password=bullshit" http://sharesix.com/auth/login
	
  Pageinit=$(curl -b "$COOKIEFILE" -e "$URL" -d "method_free=Free" $URL)
	
#	curl -b newest -L -o JurrasicII.mp4 -e "http://sharesix.com/9acamxhzz73w" http://sharesix.com/f/download/8QrzZd
	
	FILE_URL=$(echo "$Pageinit" | grep /f/download | sed 's/^[^"]*"\([^"]*\)".*/\1/')

	FILE_URL=$(echo "http://sharesix.com$FILE_URL")

	FILENAME=$(echo "$Pageinit" | grep Filename -A1 | tail -n1 | sed -e 's/******<dd>\(.*\)<\/dd>/\1/')
	
	curl -b "$COOKIEFILE" -L -o "$FILENAME" -e "$URL" "$FILE_URL"
	
	echo "$FILE_URL"
	echo "$FILENAME"
}
